package com.five.api.service.impl;

import com.five.api.dao.ArticleLabelMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.five.api.dao.LabelMapper;
import com.five.api.service.LabelService;
import com.five.entity.ArticleLabel;
import com.five.entity.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 标签表 服务实现类
 * </p>
 *
 * @author star
 * @since 2021-06-16
 */
@Service
public class LabelServiceImpl extends ServiceImpl<LabelMapper, Label> implements LabelService {

    @Autowired
    private ArticleLabelMapper articleLabelMapper;

    @Override
    public int insertLabel(Long userId, String labelName) {
        return baseMapper.insertLabel(userId, labelName);
    }

    @Override
    public int deleteLabel(Long id) {
        QueryWrapper<ArticleLabel> wrapper = new QueryWrapper<>();
        wrapper.eq("label_id",id);
        articleLabelMapper.delete(wrapper);
        return baseMapper.deleteById(id);
    }

    @Override
    public int updateLabel(Long id, String labelName) {

        return baseMapper.updateLabel(id,labelName);
    }

    @Override
    public List<Label> selectLabelByUserId(Long userId) {
        QueryWrapper<Label> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Label> labels = baseMapper.selectList(wrapper);
        return labels;
    }
}
